package cn.com.dycc.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 利用正则表达式
 * @author linfa
 *
 */

public class IntegerUtil {
	
	//判断是否是整型数字
	public static boolean isNumeric(String str){
	       Pattern pattern = Pattern.compile("[0-9]+");
	       Matcher isNum = pattern.matcher(str);
	       if( !isNum.matches() ){
	           return false;
	       }
	       return true;
	}
	
	//判断是否为正确的手机号码
	public static boolean isMobile(String str) {  
		
		Pattern p = null;  
		Matcher m = null;  
		boolean b = false;  
		p = Pattern.compile("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$"); // 验证手机号  
		m = p.matcher(str);  
		b = m.matches();  
		return b;  
	} 
	
	//判断是否为电话号码
	 public static boolean isPhone(String str) {  
	     Pattern p1 = null;
	     Pattern p2 = null;  
	     Matcher m = null;  
	     boolean b = false;  
	     p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$");  // 验证带区号的  
	     p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$");         // 验证没有区号的  
	     if (str.length() > 9) {  
	        m = p1.matcher(str);  
	        b = m.matches();  
	     } else {  
	         m = p2.matcher(str);  
	         b = m.matches();  
	     }  
	     return b;  
	 }   
	
	public static void main(String[] args) {
		String str = "1";
		Integer str1 = 123;
		boolean i = IntegerUtil.isNumeric(str);
		boolean j = IntegerUtil.isNumeric(str1.toString());
		
		boolean k = IntegerUtil.isMobile("");
		boolean o = IntegerUtil.isPhone("1234567");
		
		System.out.println(i);
		System.out.println(j);
		System.out.println(k);
		System.out.println(o);
		System.out.println("1234567".length());
	}

}
